package cn.com.infohold.smartcity.data;

import java.util.Locale;

import library.utils.XmlEditor;

/**
 * Created by HKYS on 2016-8-10.
 */

public class XmlSettings extends XmlEditor {
    private static final String sound = "sound";
    private static final String vibrate = "vibrate";
    private static final String statusbar = "statusbar";
    private static final String notification = "notification";
    private static final String light = "notification";

    private static final String language = "language";
    private static final String SHOW_EMPTY_DATA_MARKER = "show_empty_data_marker";

    @Override
    protected boolean isAutoCommit() {
        return true;
    }

    private static XmlSettings obtain() {
        return new XmlSettings();
    }

    public static void setSound(boolean sw) {
        obtain().putBoolean(sound, sw);
    }

    public static boolean getSound() {
        return obtain().getBoolean(sound, true);
    }

    public static void setVibrate(boolean sw) {
        obtain().putBoolean(vibrate, sw);
    }

    public static boolean getVibrate() {
        return obtain().getBoolean(vibrate, true);
    }

    public static void setStatusbar(boolean sw) {
        obtain().putBoolean(statusbar, sw);
    }

    public static boolean getStatusbar() {
        return obtain().getBoolean(statusbar, true);
    }

    public static void setNotification(boolean sw) {
        obtain().putBoolean(notification, sw);
    }

    public static boolean getNotification() {
        return obtain().getBoolean(notification, true);
    }

    public static void setLight(boolean sw) {
        obtain().putBoolean(light, sw);
    }

    public static boolean getLight() {
        return obtain().getBoolean(light, true);
    }

    public static void setLanguage(Locale lang) {
        if (lang != null)
            obtain().putSerializable(language, lang);
    }

    public static Locale getLanguage() {
        Locale locale = null;
        try {
            locale = (Locale) obtain().getSerializable(language);
        } catch (Exception ignore) {

        }
        if (locale == null)
            return Locale.SIMPLIFIED_CHINESE;
        return locale;
    }


    public static void setShowEmptyDataMarker(boolean sw) {
        obtain().putBoolean(SHOW_EMPTY_DATA_MARKER, sw);
    }

    public static boolean isShowEmptyDataMarker() {
        return obtain().getBoolean(SHOW_EMPTY_DATA_MARKER, false);
    }

}
